<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // new关键字过程

        // 1.call方法
        function Person(name, age) {
            this.name = name,
                this.age = age
        }
        var student = { sex: '男' }
        Person.call(student, '胖鸡', 18)
        console.log(student)

        // 2.apply方法
        // 传值格式必须使用数组方式
        function Person2(name, age) {
            this.name = name,
                this.age = age
        }
        var student2 = { sex: '女' }
        Person.apply(student2, ['胖鸡Brave', 20])
        console.log(student2)

        // 3.bind方法
        // 使用bind不会马上调用函数执行，而是返回一个this指向stu3的函数
        function Person3(name, age) {
            this.name = name,
                this.age = age
        }
        var student3 = { sex: '人妖' }
        var fn = Person3.bind(student3, '胖鸡Brae-Y', 22)
        fn() // 调用执行，给传入stu3对象，绑定属性
        console.log(student3)
    </script>

</body>

</html>